package com.yz.jdd.module.settings;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.kyleduo.switchbutton.SwitchButton;
import com.warkiz.widget.IndicatorSeekBar;
import com.warkiz.widget.OnSeekChangeListener;
import com.warkiz.widget.SeekParams;
import com.yunzong.permissions.Permission;
import com.yunzong.permissions.XXPermissions;
import com.yz.jdd.R;
import com.yz.jdd.base.MyApplication;
import com.yz.jdd.base.activity.BaseActivity;
import com.yz.jdd.base.utils.BaseConfigs;
import com.yz.jdd.base.utils.Constants;
import com.yz.jdd.base.utils.LogUtils;
import com.yz.jdd.base.utils.PreferencesUtils;
import com.yz.jdd.module.help.HelpActivity;

import com.yz.jdd.module.settings.model.LimitCondition;
import com.yz.jdd.module.settings.model.Shop;
import com.yz.jdd.module.settings.model.VoiceConfig;
import com.yz.jdd.module.settings.precenter.VoiceSettingPresenter;
import com.yz.jdd.module.settings.view.VoiceSettingView;
import com.yz.jdd.network.request.Request_shopList;
import com.yz.jdd.network.request.Request_userSwitchSetting;
import com.yz.jdd.network.response.Response_AppVoiceSet;
import com.yz.jdd.network.response.Response_UserSwitchSetting;


import com.yz.jdd.module.main.ChooseShopActivity;

import com.yz.jdd.voice.OrderVoice;
import com.yz.jdd.voice.SpeechUtilOffline;
import com.yz.jdd.webview.Router;
import com.yz.jdd.module.main.entity.ShopListItem.ResultObjectBean.PageDataBean.ShopsBean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class SettingsActivity extends BaseActivity implements
        VoiceSettingView, View.OnClickListener,
        CompoundButton.OnCheckedChangeListener,
        OnSeekChangeListener {
    ImageView top_back;
    TextView top_title;
    TextView text_shop;
    TextView text_select_shop;
    LinearLayout parentLayout;
    TextView test_voice;
    TextView help_voice;

    /**
     * 收款码收款
     */
    SwitchButton switch_code_pay;
    Button btn_code_pay;
    TextView text_select_code;
    TextView text_code;
    View divider_code_pay;
    SwitchButton switch_exe_pay;
    Button btn_exe_pay;
    SwitchButton switch_pos_pay;
    Button btn_pos_pay;
    TextView text_select_pos;
    TextView text_select_posSn;
    View divider_pos_pay;

    SwitchButton switch_box_pay;
    Button btn_box_pay;
    TextView text_select_box;
    TextView text_select_boxSn;
    View divider_box_pay;

    /**
     * 马卡龙收款
     */
    SwitchButton switch_mkl_pay;
    Button btn_mkl_pay;
    TextView text_select_mkl;
    TextView text_select_mklSn;
    View divider_mkl_pay;


    /**
     * 快小盒收款
     */
    SwitchButton switch_kxh_pay;
    Button btn_kxh_pay;
    TextView text_select_kxh;
    TextView text_select_kxhSn;
    View divider_kxh_pay;


    SwitchButton switch_cancel_order;

    SwitchButton switch_combine_order;
    /**
     * 本地收款语音开关
     */
    SwitchButton switch_local_receivables;

    LinearLayout layout_order_cancel_amount;
    SwitchButton switch_order_cancel_amount;

    IndicatorSeekBar seekbar_voice_speed;

    TextView question;
    VoiceSettingPresenter presenter;

    ShopsBean shopsBean;

    String shopId;
    String shopName;

    Button layout_cancel_order;
    int voiceSpeed = 0;

    List<LimitCondition> limitConditions;

    Response_AppVoiceSet response_appVoiceSet;

    List<Response_UserSwitchSetting> responseUserSwitchSettingList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        presenter = new VoiceSettingPresenter(this);
        initView();
        presenter.getVoiceStatus();

    }

    @Override
    protected void onDestroy() {
        if (presenter != null) {
            presenter = null;
        }

        super.onDestroy();
    }

    private void initView() {
        top_back = (ImageView) findViewById(R.id.top_back);
        top_back.setVisibility(View.VISIBLE);
        top_back.setOnClickListener(this);

        top_title = (TextView) findViewById(R.id.top_title);
        top_title.setText("语音播报设置");
        top_title.setVisibility(View.VISIBLE);


        parentLayout = findViewById(R.id.parentLayout);


        text_shop = (TextView) findViewById(R.id.text_shop);
        text_select_shop = (TextView) findViewById(R.id.text_select_shop);
        text_select_shop.setOnClickListener(this);
        text_shop.setOnClickListener(this);



        divider_code_pay = findViewById(R.id.divider_code_pay);

        test_voice = (TextView) findViewById(R.id.test_voice);
        test_voice.setOnClickListener(this);

        help_voice = (TextView) findViewById(R.id.help_voice);
        help_voice.setOnClickListener(this);

        layout_order_cancel_amount = (LinearLayout) findViewById(R.id.layout_order_cancel_amount);
        switch_cancel_order = (SwitchButton) findViewById(R.id.switch_cancel_order);

        layout_cancel_order = (Button) findViewById(R.id.layout_cancel_order);
        layout_cancel_order.setOnClickListener(this);

        /**
         * 收款码
         */
        switch_code_pay = findViewById(R.id.switch_code_pay);
        switch_code_pay.setOnCheckedChangeListener(this);
        btn_code_pay = findViewById(R.id.btn_code_pay);
        btn_code_pay.setOnClickListener(this);
        text_code = (TextView) findViewById(R.id.text_code);
        text_select_code = (TextView) findViewById(R.id.text_select_code);
        text_select_code.setOnClickListener(this);

        /**
         * exe收款
         */
        switch_exe_pay = findViewById(R.id.switch_exe_pay);
        switch_exe_pay.setOnCheckedChangeListener(this);
        btn_exe_pay = findViewById(R.id.btn_exe_pay);
        btn_exe_pay.setOnClickListener(this);


        /**
         * POS收款
         */
        switch_pos_pay = findViewById(R.id.switch_pos_pay);
        switch_pos_pay.setOnCheckedChangeListener(this);
        btn_pos_pay = findViewById(R.id.btn_pos_pay);
        btn_pos_pay.setOnClickListener(this);
        text_select_pos = findViewById(R.id.text_select_pos);
        text_select_posSn = findViewById(R.id.text_select_posSn);
        text_select_posSn.setOnClickListener(this);
        divider_pos_pay = findViewById(R.id.divider_pos_pay);


        /**
         * 智慧盒子收款
         */
        switch_box_pay = findViewById(R.id.switch_box_pay);
        switch_box_pay.setOnCheckedChangeListener(this);
        btn_box_pay = findViewById(R.id.btn_box_pay);
        btn_box_pay.setOnClickListener(this);
        text_select_box = findViewById(R.id.text_select_box);
        text_select_boxSn = findViewById(R.id.text_select_boxSn);
        text_select_boxSn.setOnClickListener(this);
        divider_box_pay = findViewById(R.id.divider_box_pay);

        /**
         * 马卡龙收款
         */
        switch_mkl_pay = findViewById(R.id.switch_mkl_pay);
        switch_mkl_pay.setOnCheckedChangeListener(this);
        btn_mkl_pay = findViewById(R.id.btn_mkl_pay);
        btn_mkl_pay.setOnClickListener(this);
        text_select_mkl = findViewById(R.id.text_select_mkl);
        text_select_mklSn = findViewById(R.id.text_select_mklSn);
        text_select_mklSn.setOnClickListener(this);
        divider_mkl_pay = findViewById(R.id.divider_mkl_pay);

        /**
         * 快小盒收款
         */
        switch_kxh_pay = findViewById(R.id.switch_kxh_pay);
        switch_kxh_pay.setOnCheckedChangeListener(this);
        btn_kxh_pay = findViewById(R.id.btn_kxh_pay);
        btn_kxh_pay.setOnClickListener(this);
        text_select_kxh = findViewById(R.id.text_select_kxh);
        text_select_kxhSn = findViewById(R.id.text_select_kxhSn);
        text_select_kxhSn.setOnClickListener(this);
        divider_kxh_pay = findViewById(R.id.divider_kxh_pay);



        switch_local_receivables = (SwitchButton) findViewById(R.id.switch_local_receivables);
        switch_local_receivables.setOnCheckedChangeListener(this);
        switch_local_receivables.setCheckedImmediatelyNoEvent(PreferencesUtils.getBoolean(this, BaseConfigs.BOOLEAN_LOCAL_RECEIVABLES, true));
        switch_combine_order = (SwitchButton) findViewById(R.id.switch_combine_order);


        switch_combine_order.setOnCheckedChangeListener(this);
        switch_combine_order.setCheckedImmediatelyNoEvent(PreferencesUtils.getBoolean(this, BaseConfigs.BOOLEAN_COMBINE_ORDER));

        switch_order_cancel_amount = (SwitchButton) findViewById(R.id.switch_order_cancel_amount);
        switch_order_cancel_amount.setOnCheckedChangeListener(this);

        switch_order_cancel_amount.setCheckedImmediatelyNoEvent(PreferencesUtils.getBoolean(this, BaseConfigs.BOOLEAN_ORDER_CANCEL_AMOUNT));

        seekbar_voice_speed = (IndicatorSeekBar) findViewById(R.id.seekbar_voice_speed);
        seekbar_voice_speed.setOnSeekChangeListener(this);

        int voiceSpeed = PreferencesUtils.getInt(MyApplication.application, BaseConfigs.INT_VOICE_SPEED, 0);
        seekbar_voice_speed.setProgress(voiceSpeed * 50);

        question = (TextView) findViewById(R.id.question);
        question.setOnClickListener(this);

    }

    @Override
    protected void onResume() {

        super.onResume();

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_back) {
            finish();
        } else if (view.getId() == R.id.test_voice) {
            if (XXPermissions.isHasPermission(this, Permission.READ_PHONE_STATE)){
                try {
                    OrderVoice orderVoice = new OrderVoice();
                    orderVoice.setContent(Constants.BRAND_VOICE+"收款100元");

                    SpeechUtilOffline.getInstance(getApplicationContext()).play(orderVoice, SpeechUtilOffline.PLAY_MODE.QUEUED);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }

        } else if (view.getId() == R.id.text_select_shop || view.getId() == R.id.text_shop) {
            //打开门店选择
            Intent intent = new Intent(new Intent(SettingsActivity.this, ChooseShopActivity.class));
            intent.putExtra("isSettingsActivity", true);
            startActivityForResult(intent, Constants.SettingsActivityForResultCode);

        } else if (view.getId() == R.id.question) {
            Router.startNewWebView(this, Router.questionPage, "", "", true);
        } else if (view.getId() == R.id.help_voice) {
            startActivity(new Intent(this, HelpActivity.class));

        } else if (view.getId() == R.id.layout_cancel_order) {

                if(switch_code_pay.isChecked()){
                    if (switch_cancel_order.isChecked()) {
                        //0：表示关闭，1：表示开启
                        presenter.setCancelOrderSetting("0");
                    } else {
                        presenter.setCancelOrderSetting("1");
                    }
                }  else{

                    if(switch_cancel_order.isChecked()){
                        presenter.setCancelOrderSetting("0");
                    }else{
                        showToast("请先开启收款码播报收款开关");
                    }

                }

        }  else if (view.getId() == R.id.btn_code_pay) {

            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.QRCODE_VOICE);
                if (switch_code_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);
            } else {
                showToast("请先设置播报门店");
            }


        } else if (view.getId() == R.id.btn_exe_pay) {
            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.PC_COLLECTION_VOICE);
                if (switch_exe_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);
            } else {
                showToast("请先设置播报门店");
            }


        } else if (view.getId() == R.id.btn_pos_pay) {

            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.POS_COLLECTION_VOICE);
                if (switch_pos_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);
            } else {
                showToast("请先设置播报门店");
            }


        } else if (view.getId() == R.id.btn_box_pay) {

            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.SMART_BOX_COLLECTION_VOICE);
                if (switch_box_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);
            } else {
                showToast("请先设置播报门店");
            }


        } else if (view.getId() == R.id.btn_mkl_pay) {

            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.MKL_COLLECTION_VOICE);
                if (switch_mkl_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);
            } else {
                showToast("请先设置播报门店");
            }


        } else if (view.getId() == R.id.btn_kxh_pay) {

            String shopNameStr = text_select_shop.getText().toString();
            if (!"设置门店".equals(shopNameStr)) {
                Request_userSwitchSetting userSwitchSetting = new Request_userSwitchSetting();
                userSwitchSetting.setSwitchType(VoiceConfig.VoiceType.BOX_COLLECTION_VOICE);
                if (switch_kxh_pay.isChecked()) {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.CLOSED);
                } else {
                    userSwitchSetting.setSwitchSet(VoiceConfig.SwitchSetStatus.OPENNING);
                }
                presenter.doUserSwitchSetting(userSwitchSetting);

            } else {
                showToast("请先设置播报门店");
            }

        }else if(view.getId() == R.id.text_select_code){
            //选收款码
            Intent intent = new Intent(SettingsActivity.this, SelectCodeActivity.class);
            String shopNameStr = text_select_shop.getText().toString();
            Bundle bundle = new Bundle();
            bundle.putString("shopNameStr",shopNameStr);
            bundle.putString("shopId",shopId);
//            intent.putExtra("limitConditions", (Serializable) limitConditions);
            if(responseUserSwitchSettingList!=null){
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    if(VoiceConfig.VoiceType.QRCODE_VOICE.equals(response_userSwitchSetting.getSwitchType())){
                        //如果是 付款码l
//                    intent.putExtra("limitationList",response_userSwitchSetting.getLimitationList());
                        bundle.putSerializable("limitationList", (Serializable) response_userSwitchSetting.getLimitationList());
                        bundle.putInt("limitation",response_userSwitchSetting.getLimitation());
                    }
                }
            }

            intent.putExtras(bundle);
            startActivityForResult(intent, Constants.SelectCodeResultCode);

        }else  if(view.getId() == R.id.text_select_posSn){
            //pos
            Intent intent = new Intent(this,SelectDeviceActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("deviceType",VoiceConfig.DeviceType.POS);
            bundle.putString("shopId",shopId);
            if(responseUserSwitchSettingList!=null){
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    if(VoiceConfig.VoiceType.POS_COLLECTION_VOICE.equals(response_userSwitchSetting.getSwitchType())){
                        bundle.putSerializable("limitationList", (Serializable) response_userSwitchSetting.getLimitationList());
                        bundle.putInt("limitation",response_userSwitchSetting.getLimitation());
                    }
                }
            }
            intent.putExtras(bundle);
            startActivityForResult(intent, Constants.SelectCodeResultCode);
        }else  if(view.getId() == R.id.text_select_boxSn){
            //盒子
            Intent intent = new Intent(this,SelectDeviceActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("deviceType",VoiceConfig.DeviceType.SMART_BOX);
            bundle.putString("shopId",shopId);
            if(responseUserSwitchSettingList!=null){
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    if(VoiceConfig.VoiceType.SMART_BOX_COLLECTION_VOICE.equals(response_userSwitchSetting.getSwitchType())){
                        bundle.putSerializable("limitationList", (Serializable) response_userSwitchSetting.getLimitationList());
                        bundle.putInt("limitation",response_userSwitchSetting.getLimitation());
                    }
                }
            }
            intent.putExtras(bundle);
            startActivityForResult(intent, Constants.SelectCodeResultCode);
        }else  if(view.getId() == R.id.text_select_mklSn){
            //马卡龙
            Intent intent = new Intent(this,SelectDeviceActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("deviceType",VoiceConfig.DeviceType.MKL);
            bundle.putString("shopId",shopId);
            if(responseUserSwitchSettingList!=null){
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    if(VoiceConfig.VoiceType.MKL_COLLECTION_VOICE.equals(response_userSwitchSetting.getSwitchType())){
                        bundle.putSerializable("limitationList", (Serializable) response_userSwitchSetting.getLimitationList());
                        bundle.putInt("limitation",response_userSwitchSetting.getLimitation());
                    }
                }
            }
            intent.putExtras(bundle);
            startActivityForResult(intent, Constants.SelectCodeResultCode);
        }else  if(view.getId() == R.id.text_select_kxhSn){
            //快小盒
            Intent intent = new Intent(this,SelectDeviceActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("deviceType",VoiceConfig.DeviceType.FAST_BOX);
            bundle.putString("shopId",shopId);
            if(responseUserSwitchSettingList!=null){
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    if(VoiceConfig.VoiceType.BOX_COLLECTION_VOICE.equals(response_userSwitchSetting.getSwitchType())){
                        bundle.putSerializable("limitationList", (Serializable) response_userSwitchSetting.getLimitationList());
                        bundle.putInt("limitation",response_userSwitchSetting.getLimitation());
                    }
                }
            }
            intent.putExtras(bundle);
            startActivityForResult(intent, Constants.SelectCodeResultCode);
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Constants.SettingsActivityForResultCode) {
            Bundle bundle = data.getExtras();
            /**
             * ShopsBean
             * auditStatus : 4.0
             * branchShopName : 丁家屯店
             * mainShopName : 云纵测试门店
             * shopId : 2017022700077000000026808340
             * shopName : 云纵测试门店(丁家屯店)
             */
            shopsBean = (ShopsBean) bundle.getSerializable("shopsBean");
            shopId = shopsBean.getShopId();
            shopName = shopsBean.getShopName();
            if (!TextUtils.isEmpty(shopId)) {
//                presenter.setVoiceSetting(1, shopId, shopName);
                List shopList=new ArrayList();
                Request_shopList request_shopList=new Request_shopList();

                Shop shop=new Shop();
                shop.setShopId(shopId);
                shop.setShopName(shopName);
                shopList.add(shop);

                request_shopList.setShopList(shopList);


                presenter.doAppVoiceShopListSet(request_shopList);
//                presenter.getVoiceStatus();
            }

            LogUtils.i(shopsBean.toString());
        } else if (resultCode == Constants.SelectCodeResultCode) {
            presenter.getVoiceStatus();
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
        if (compoundButton.getId() == R.id.switch_combine_order) {
            PreferencesUtils.putBoolean(this, BaseConfigs.BOOLEAN_COMBINE_ORDER, checked);
        } else if (compoundButton.getId() == R.id.switch_order_cancel_amount) {
            PreferencesUtils.putBoolean(this, BaseConfigs.BOOLEAN_ORDER_CANCEL_AMOUNT, checked);
        } else if (compoundButton.getId() == R.id.switch_local_receivables) {
            PreferencesUtils.putBoolean(this, BaseConfigs.BOOLEAN_LOCAL_RECEIVABLES, checked);
        } else if (compoundButton.getId() == R.id.switch_code_pay) {

        } else if (compoundButton.getId() == R.id.switch_exe_pay) {

        } else if (compoundButton.getId() == R.id.switch_pos_pay) {

        } else if (compoundButton.getId() == R.id.switch_box_pay) {

        } else if (compoundButton.getId() == R.id.switch_mkl_pay) {

        } else if (compoundButton.getId() == R.id.switch_kxh_pay) {

        }

    }

    @Override
    public void showView(Response_AppVoiceSet response_voiceStatus) {
        Log.e("cancelOrderStatus", "---" + response_voiceStatus);
        if (response_voiceStatus != null) {
            response_appVoiceSet=response_voiceStatus;

            String cancelOrderStatus=VoiceConfig.SwitchSetStatus.CLOSED;
            if(response_voiceStatus.getPersonalizationSetting()!=null){
                 cancelOrderStatus=response_voiceStatus.getPersonalizationSetting().getEscapeWarnSwitch();
            }

            List<Shop> shopList = response_voiceStatus.getShopList();


            responseUserSwitchSettingList=response_voiceStatus.getUserSwitchSettings();
            if (shopList != null && shopList.size() > 0) {
                text_select_shop.setText(shopList.get(0).getShopName());
                shopName=shopList.get(0).getShopName();
                shopId =shopList.get(0).getShopId();
            } else {
                text_select_shop.setText("设置门店");
            }

            if (responseUserSwitchSettingList != null && responseUserSwitchSettingList.size() > 0) {
                for (Response_UserSwitchSetting response_userSwitchSetting : responseUserSwitchSettingList) {
                    showUserSwitchSetting(response_userSwitchSetting.getSwitchType(), response_userSwitchSetting);
                }
            }
            //有值才设置
            Log.e("cancelOrderStatus", "" + cancelOrderStatus);
            if (!TextUtils.isEmpty(cancelOrderStatus)) {
                showCancelOrderView(VoiceConfig.SwitchSetStatus.OPENNING.equals(cancelOrderStatus) ? "1" : "0");

            }

        }

    }

    @Override
    public void hidenLoading() {
        super.dismissLoading();
    }

    @Override
    public void showLoading() {
        super.showLoading("加载中...");
    }

    @Override
    public void showCancelOrderView(String status) {
        if ("1".equals(status)) {
            //开启
            switch_cancel_order.setCheckedImmediatelyNoEvent(true);
            layout_order_cancel_amount.setVisibility(View.VISIBLE);
        } else {
            //关闭
            switch_cancel_order.setCheckedImmediatelyNoEvent(false);
            layout_order_cancel_amount.setVisibility(View.GONE);

        }
    }

    @Override
    public void showUserSwitchSetting(String switchType, Response_UserSwitchSetting response_userSwitchSetting) {
        String switchSet = response_userSwitchSetting.getSwitchSet();
        switch (switchType) {
            case VoiceConfig.VoiceType.QRCODE_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_code_pay.setCheckedImmediatelyNoEvent(false);
                    text_select_code.setVisibility(View.GONE);
                    text_code.setVisibility(View.GONE);
                    divider_code_pay.setVisibility(View.GONE);
                } else {
                    switch_code_pay.setCheckedImmediatelyNoEvent(true);
                    text_select_code.setVisibility(View.VISIBLE);
                    text_code.setVisibility(View.VISIBLE);
                    divider_code_pay.setVisibility(View.VISIBLE);
                    if ((response_userSwitchSetting.getLimitation()==0)
                            || response_userSwitchSetting.getLimitationList() == null
                            || response_userSwitchSetting.getLimitationList().size() == 0) {
                        //0 不限制
                        text_select_code.setText("不限制");
                    } else if (response_userSwitchSetting.getLimitation()==1) {
                        //1 限制
                        if (response_userSwitchSetting.getLimitationList() != null && response_userSwitchSetting.getLimitationList().size() > 0) {
                            text_select_code.setText("已选择" + response_userSwitchSetting.getLimitationList().size() + "个");
                        }
                    }

                }
                break;
            case VoiceConfig.VoiceType.PC_COLLECTION_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_exe_pay.setCheckedImmediatelyNoEvent(false);

                } else {
                    switch_exe_pay.setCheckedImmediatelyNoEvent(true);
                }

                break;
            case VoiceConfig.VoiceType.POS_COLLECTION_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_pos_pay.setCheckedImmediatelyNoEvent(false);
                    text_select_pos.setVisibility(View.GONE);
                    text_select_posSn.setVisibility(View.GONE);
                    divider_pos_pay.setVisibility(View.GONE);
                } else {
                    switch_pos_pay.setCheckedImmediatelyNoEvent(true);
                    text_select_pos.setVisibility(View.VISIBLE);
                    text_select_posSn.setVisibility(View.VISIBLE);
                    divider_pos_pay.setVisibility(View.VISIBLE);
                    if (response_userSwitchSetting.getLimitation()==0
                            || response_userSwitchSetting.getLimitationList() == null
                            || response_userSwitchSetting.getLimitationList().size() == 0) {
                        //0 不限制
                        text_select_posSn.setText("不限制");
                    } else if (response_userSwitchSetting.getLimitation()==1) {
                        //1 限制
                        if (response_userSwitchSetting.getLimitationList() != null && response_userSwitchSetting.getLimitationList().size() > 0) {
                            text_select_posSn.setText("已选择" + response_userSwitchSetting.getLimitationList().size() + "个");
                        }
                    }

                }
                break;
            case VoiceConfig.VoiceType.SMART_BOX_COLLECTION_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_box_pay.setCheckedImmediatelyNoEvent(false);
                    text_select_box.setVisibility(View.GONE);
                    text_select_boxSn.setVisibility(View.GONE);
                    divider_box_pay.setVisibility(View.GONE);
                } else {
                    switch_box_pay.setCheckedImmediatelyNoEvent(true);
                    text_select_box.setVisibility(View.VISIBLE);
                    text_select_boxSn.setVisibility(View.VISIBLE);
                    divider_box_pay.setVisibility(View.VISIBLE);
                    if (response_userSwitchSetting.getLimitation()==0
                            || response_userSwitchSetting.getLimitationList() == null
                            || response_userSwitchSetting.getLimitationList().size() == 0) {
                        //0 不限制
                        text_select_boxSn.setText("不限制");
                    } else if (response_userSwitchSetting.getLimitation()==1) {
                        //1 限制
                        if (response_userSwitchSetting.getLimitationList() != null && response_userSwitchSetting.getLimitationList().size() > 0) {
                            text_select_boxSn.setText("已选择" + response_userSwitchSetting.getLimitationList().size() + "个");
                        }
                    }

                }
                break;
            case VoiceConfig.VoiceType.MKL_COLLECTION_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_mkl_pay.setCheckedImmediatelyNoEvent(false);
                    text_select_mkl.setVisibility(View.GONE);
                    text_select_mklSn.setVisibility(View.GONE);
                    divider_mkl_pay.setVisibility(View.GONE);
                } else {
                    switch_mkl_pay.setCheckedImmediatelyNoEvent(true);
                    text_select_mkl.setVisibility(View.VISIBLE);
                    text_select_mklSn.setVisibility(View.VISIBLE);
                    divider_mkl_pay.setVisibility(View.VISIBLE);
                    if (response_userSwitchSetting.getLimitation()==0
                            || response_userSwitchSetting.getLimitationList() == null
                            || response_userSwitchSetting.getLimitationList().size() == 0) {
                        //0 不限制
                        text_select_mklSn.setText("不限制");
                    } else if (response_userSwitchSetting.getLimitation()==1) {
                        //1 限制
                        if (response_userSwitchSetting.getLimitationList() != null && response_userSwitchSetting.getLimitationList().size() > 0) {
                            text_select_mklSn.setText("已选择" + response_userSwitchSetting.getLimitationList().size() + "个");
                        }
                    }

                }
                break;
            case VoiceConfig.VoiceType.BOX_COLLECTION_VOICE:
                if (VoiceConfig.SwitchSetStatus.CLOSED.equals(switchSet)) {
                    switch_kxh_pay.setCheckedImmediatelyNoEvent(false);
                    text_select_kxh.setVisibility(View.GONE);
                    text_select_kxhSn.setVisibility(View.GONE);
                    divider_kxh_pay.setVisibility(View.GONE);
                } else {
                    switch_kxh_pay.setCheckedImmediatelyNoEvent(true);
                    text_select_kxh.setVisibility(View.VISIBLE);
                    text_select_kxhSn.setVisibility(View.VISIBLE);
                    divider_kxh_pay.setVisibility(View.VISIBLE);
                    if (response_userSwitchSetting.getLimitation()==0
                            || response_userSwitchSetting.getLimitationList() == null
                            || response_userSwitchSetting.getLimitationList().size() == 0) {
                        //0 不限制
                        text_select_kxhSn.setText("不限制");
                    } else if (response_userSwitchSetting.getLimitation()==1) {
                        //1 限制
                        if (response_userSwitchSetting.getLimitationList() != null && response_userSwitchSetting.getLimitationList().size() > 0) {
                            text_select_kxhSn.setText("已选择" + response_userSwitchSetting.getLimitationList().size() + "个");
                        }
                    }

                }
                break;

            default:

        }
    }

    @Override
    public void onSeeking(SeekParams seekParams) {

        voiceSpeed = seekParams.thumbPosition;
    }

    @Override
    public void onStartTrackingTouch(IndicatorSeekBar indicatorSeekBar) {

    }

    @Override
    public void onStopTrackingTouch(IndicatorSeekBar indicatorSeekBar) {
//        Log.e("lkf", voiceSpeed + "");
        PreferencesUtils.putInt(this, BaseConfigs.INT_VOICE_SPEED, voiceSpeed);
    }
}
